# Maintainer : Christian Rebischke <chris.rebischke@archlinux.org>
# Contributor: Fernandez Ludovic <lfernandez dot dev at gmail dot com>

pkgname='goreleaser'
pkgver=1.22.1
pkgrel=1
pkgdesc='Deliver Go binaries as fast and easily as possible'
url='https://goreleaser.com'
arch=('loong64' 'x86_64')
license=('MIT')
depends=('glibc')
makedepends=('git' 'go')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/goreleaser/goreleaser/archive/v${pkgver}.tar.gz")
sha512sums=('2a11e381803d2c867f253e57b40e065473797b9bd2edabb1e64061d8cc2e653545f8c6f27f5adbca67cc61add211062b6de4c0c9e5f3a88a72165a3791ce4ab3')
b2sums=('1fd1badc1c02c4487299b83bf2ba47d4f88247c4aca0fb972d81ac5c69906b5cea43ca45aecb32dfa38bb2b8df95d0bc0b6f129f3fc2a52cb5e1dfb682912687')

build() {
  cd "${pkgname}-${pkgver}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  go build -ldflags="-w -s -buildid='' -linkmode=external -X main.version=${pkgver}" .
  chmod +x ./goreleaser
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dsm755 ./goreleaser "${pkgdir}/usr/bin/goreleaser"
  mkdir -p "${pkgdir}/usr/share/bash-completion/completions/"
  mkdir -p "${pkgdir}/usr/share/zsh/site-functions/"
  mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d/"
  ./goreleaser completion bash > "${pkgdir}/usr/share/bash-completion/completions/goreleaser"
  ./goreleaser completion zsh > "${pkgdir}/usr/share/zsh/site-functions/_goreleaser"
  ./goreleaser completion fish > "${pkgdir}/usr/share/fish/vendor_completions.d/goreleaser.fish"
}
